home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / util / cdity / ModeProSrc.lha / Daemon / OldPatch / LockPubScreenListPatch.c < prev    next >
C/C++ Source or Header  |  1998-09-10  |  4KB  |  149 lines

  1. //#define DEBUG
  2.  
  3. #include "MP.h"
  4. #include <debug.h>
  5. #include <exec/lists.h>
  6.  
  7. extern struct MPSem *MPSem;
  8.  
  9. // LockPubScreenList
  10. extern struct List * __asm (*OldLockPubScreenList)(register __a6 struct Library *);
  11. extern void __asm (*OldUnlockPubScreenList)(register __a6 struct Library *);
  12.   
  13. struct List PubScreenList;
  14. LONG PubListNest=0; // If Zero then Init 
  15.  
  16. #define PSNF_FAKE (1<<15) // Fake psn_Flags
  17.  
  18. struct List *IntuitionPubScreenList;
  19.  
  20. struct List * __saveds __asm NewLockPubScreenList(register __a6 struct IntuitionBase *IBase)
  21. {
  22.   struct PubScreenNode *psn,*npsn;
  23.   struct DefaultNode *dnode;
  24.   struct List *list;
  25.   struct Task faketask={0};
  26.   struct Screen *fakescr;
  27.   
  28.   char tnamebuffer[52];
  29.   char *tname;
  30.   
  31.   tname=SetupTaskName(tnamebuffer,", LPSL",50);
  32.   
  33. DEBUG_CODE(
  34.   DKP("LockPubScreenList()\n");
  35.   )  
  36.  
  37.   ObtainSemaphoreShared(&MPSem->ListSem); 
  38.   ObtainSemaphore(&MPSem->NodeSem);
  39.   
  40.   IntuitionPubScreenList=list=OldLockPubScreenList((struct Library *)IBase);
  41.  
  42.   /* Clone Old PS list */
  43.   
  44.   if(PubListNest==0)
  45.   {
  46.     // The OS nests calls to LockPubScreenList()/UnlockPubScreenList() only create the list when PubListNest==0
  47.  
  48.     /* Make PSNodes for MP's pubscreens */
  49.     
  50.     dnode=(struct DefaultNode *)MPSem->PromotionList[PL_PUBLICSCREENS].lh_Head;
  51.   
  52.     psn=(APTR)list->lh_Head;
  53.     
  54.     if(psn->psn_Node.ln_Succ)
  55.     {
  56.       while(dnode->Def_Node.ln_Succ)
  57.       {
  58.         if(!FindName(list,dnode->Def_Node.ln_Name))
  59.         { /* Avoid Duplicates */
  60.           if(npsn=AllocVec(sizeof(*npsn),MEMF_PUBLIC|MEMF_CLEAR))
  61.           {
  62.             if(fakescr=AllocVec(sizeof(*fakescr),MEMF_PUBLIC|MEMF_CLEAR))
  63.             {
  64.               /* Screen */
  65.               fakescr->Width=dnode->Width;
  66.               fakescr->Height=dnode->Height;
  67.               fakescr->Title=dnode->Def_Node.ln_Name;
  68.               fakescr->RastPort.BitMap=&fakescr->BitMap;
  69.               fakescr->BitMap.Depth=dnode->Depth;
  70.               
  71.               npsn->psn_Node.ln_Name=dnode->Def_Node.ln_Name; // Safe to reference name since lists are protected till UnlockPubScreenList() 
  72.               npsn->psn_Flags=PSNF_FAKE;
  73.               npsn->psn_SigTask=&faketask;
  74.               npsn->psn_Screen=fakescr; // Hmmm
  75.               AddTail(list,(struct Node *)npsn);
  76.             }
  77.             else
  78.             {
  79.               FreeVec(npsn);
  80.             }
  81.           }
  82.         }
  83.         dnode=(struct DefaultNode *)dnode->Def_Node.ln_Succ;
  84.       }
  85.     }
  86.   }
  87.   else
  88.   {
  89.     // nested
  90.   }
  91.  
  92.  
  93. /*
  94.   {
  95.     LONG *l,q;
  96.     
  97.     l=0;
  98.     
  99.     *l=0;
  100.   }*/
  101.   
  102.   PubListNest++; // Some dumb apps call LockPubScreen() inside LockPubScreenList()/UnlockPubScreenList()
  103.   
  104.   SetTaskName(tname);
  105.   
  106.   return(list);
  107. }
  108.  
  109. void __saveds __asm NewUnlockPubScreenList(register __a6 struct IntuitionBase *IBase)
  110. {
  111.   struct PubScreenNode *psn,*p2;
  112.   
  113.   PubListNest--;
  114.   
  115.   
  116.   if(PubListNest==0)
  117.   {
  118.     psn=(APTR)IntuitionPubScreenList->lh_Head;
  119.     
  120.     while(psn->psn_Node.ln_Succ)
  121.     {
  122.       DKP("psn=%8lx %s\n",psn,psn->psn_Node.ln_Name);
  123.       if(psn->psn_Flags & PSNF_FAKE)
  124.       {
  125.         DKP("  free psn\n");
  126.         p2=(APTR)psn->psn_Node.ln_Succ;
  127.         Remove((APTR)psn);
  128.         FreeVec(psn->psn_Screen);  // screen is fake to!
  129.         FreeVec(psn);
  130.         psn=p2;
  131.       }
  132.       else
  133.       {
  134.         psn=(APTR)psn->psn_Node.ln_Succ;
  135.       }
  136.     }
  137.   }
  138.   
  139.   OldUnlockPubScreenList((struct Library *)IBase);
  140.   
  141.   
  142. DEBUG_CODE(
  143.   DKP("UnlockPubScreenList()\n");
  144.   )  
  145.  
  146.   ReleaseSemaphore(&MPSem->NodeSem);      
  147.   ReleaseSemaphore(&MPSem->ListSem);
  148. }
  149.